< previous page page_109 next page >

Page 109
0109-01.jpg
Figure 3.11
Example program SysMap displays the mapping between
an image's logical color palette and the system color palette.
has index 0 in the system palette. Because these entries are flagged PC_NOCOLLAPSE, they are placed at the next available system palette entries starting after the first block of static colors.
Now use SetPaletteEntries again to redefine the non-static colors so that they have the final values you want. Be sure to keep their flags set to PC_NOCOLLAPSE.
You can use this method to make each logical palette entry for an image map to the corresponding system palette entry. First, load an image and realize its palette. This step makes the system load the logical palette into the system palette in some unknown order. Next, use GetSystemPaletteEntries to retrieve the system palette entries. Then use the previous technique to copy the colors in the system palette into the logical palette. When you are finished, the colors in the logical palette correspond to those in the system palette.
Subroutine LoadLogicalPalette, shown in the following code, uses this method to load the logical palette for picture box ImagePict into the system palette. It first realizes the palette for ImagePict so that the system palette contains the colors in the logical palette. The routine next uses GetSystemPaletteEntries to identify the colors loaded in the system palette. It then reloads the static colors into the system palette, turning all the other colors black. Finally, it updates the non-static colors in the logical palette so that they match those in the system palette.
e10a6a0a59f035e870d90cca05b85fce.gif
' Load the picHidden palette so its entries
' match the system entries.
Private Sub LoadLogicalPalette()
Dim palentry(0 To 255) As PALETTEENTRY
Dim blanked(0 To 255) As PALETTEENTRY
Dim i As Integer

    ' Make picVisible and picSwatch use the same

 
< previous page page_109 next page >